home *** CD-ROM | disk | FTP | other *** search
/ 45 Great Windows Utilities 6 / 45 Great Windows Utilities Volume 6 MOJO-405 (Mojo Software).iso / ss / libentry.asm < prev    next >
Assembly Source File  |  1990-11-02  |  2KB  |  77 lines

  1. PAGE,132
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;
  4. ;       LIBENTRY.ASM
  5. ;
  6. ;       Windows dynamic link library entry routine
  7. ;
  8. ;   This module generates a code segment called INIT_TEXT.
  9. ;   It initializes the local heap if one exists and then calls
  10. ;   the C routine LibMain() which should have the form:
  11. ;   BOOL FAR PASCAL LibMain(HANDLE hInstance,
  12. ;                           WORD   wDataSeg,
  13. ;                           WORD   cbHeap,
  14. ;                           LPSTR  lpszCmdLine);
  15. ;        
  16. ;   The result of the call to LibMain is returned to Windows.
  17. ;   The C routine should return TRUE if it completes initialization
  18. ;   successfully, FALSE if some error occurs.
  19. ;
  20. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  21.  
  22. include cmacros.inc
  23.  
  24. externFP <LibMain>               ; the C routine to be called
  25.  
  26. createSeg INIT_TEXT, INIT_TEXT, BYTE, PUBLIC, CODE
  27. sBegin  INIT_TEXT
  28. assumes CS,INIT_TEXT
  29.  
  30. ?PLM=0                           ; 'C'naming
  31. externA  <_acrtused>             ; ensures that Win DLL startup code is linked
  32.  
  33. ?PLM=1                           ; 'PASCAL' naming
  34. externFP <LocalInit>             ; Windows heap init routine
  35.  
  36. cProc   LibEntry, <PUBLIC,FAR>   ; entry point into DLL
  37.  
  38. cBegin
  39.         push    di               ; handle of the module instance
  40.         push    ds               ; library data segment
  41.         push    cx               ; heap size
  42.         push    es               ; command line segment
  43.         push    si               ; command line offset
  44.  
  45.         ; if we have some heap then initialize it
  46.         jcxz    callc            ; jump if no heap specified
  47.  
  48.         ; call the Windows function LocalInit() to set up the heap
  49.         ; LocalInit((LPSTR)start, WORD cbHeap);
  50.         
  51.         xor     ax,ax
  52.         cCall   LocalInit <ds, ax, cx>
  53.         or      ax,ax            ; did it do it ok ?
  54.         jz      error            ; quit if it failed
  55.  
  56.         ; invoke the C routine to do any special initialization
  57.  
  58. callc:
  59.         call    LibMain          ; invoke the 'C' routine (result in AX)
  60.         jmp short exit           ; LibMain is responsible for stack clean up
  61.  
  62. error:
  63.         pop     si               ; clean up stack on a LocalInit error
  64.         pop     es               
  65.         pop     cx               
  66.         pop     ds
  67.         pop     di
  68.  
  69. exit:
  70.  
  71. cEnd
  72.  
  73. sEnd    INIT_TEXT
  74.  
  75. end LibEntry
  76. 
  77.